package com.wdy.po;

import java.io.Serializable;
import java.util.Set;

import com.wdy.util.BasicUtil;

@SuppressWarnings({"unchecked","serial"})
public class User implements Comparable, Serializable {

	private Integer uid;
	private String username;
	private String password;
	private String privilege;
	private Tenement tenement;
	private Set<Post> posts;
	
	public User() {
		super();
	}

	public User(Integer uid, String username, String password,
			String privilege, Tenement tenement, Set<Post> posts) {
		super();
		this.uid = uid;
		this.username = username;
		this.password = password;
		this.privilege = privilege;
		this.tenement = tenement;
		this.posts = posts;
	}

	public Integer getUid() {
		return uid;
	}

	public void setUid(Integer uid) {
		this.uid = uid;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPrivilege() {
		return privilege;
	}

	public void setPrivilege(String privilege) {
		this.privilege = privilege;
	}
	
	public Tenement getTenement() {
		return tenement;
	}

	public void setTenement(Tenement tenement) {
		this.tenement = tenement;
	}

	public Set<Post> getPosts() {
		return posts;
	}

	public void setPosts(Set<Post> posts) {
		this.posts = posts;
	}
/*
	@Override
	public boolean equals(Object o) {
		if(null == o) {
			return false;
		}
		if(o instanceof User){
			User contrastUser = (User)o;
			Integer contrastUid = contrastUser.getUid();
			String contrastUsername = contrastUser.getUsername();
			if(this.uid.equals(contrastUid) && BasicUtil.isNullOrEmpty(this.username, contrastUsername)){
				return true;
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		return this.uid.hashCode() * this.username.hashCode();
	}
*/
	@Override
	public String toString() {
		return this.username;
	}

	public int compareTo(Object o) {
		User contrastUser = (User)o;
		Integer contrastUid = contrastUser.getUid();
		int orignalId = this.uid.intValue();
		int contrastId = contrastUid.intValue();
		return BasicUtil.compare(orignalId, contrastId);
	}

 
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((uid == null) ? 0 : uid.hashCode());
		result = prime * result
				+ ((username == null) ? 0 : username.hashCode());
		return result;
	}

	 
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof User))
			return false;
		final User other = (User) obj;
		if (uid == null) {
			if (other.uid != null)
				return false;
		} else if (!uid.equals(other.uid))
			return false;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		return true;
	}
}
